package com.wtpaint.lib.db.db;

import android.database.sqlite.SQLiteDatabase;

/**
 * Created by leoxu on 2018/11/17.
 */

public class ZeusDbHelper {

    private static ZeusDbHelper mInstance;

    private SQLiteDatabase mSqLiteDatabase;

    private String mPath;

    private ZeusDbHelper() {
        mPath = "data/data/com.wtpaint.zeuslib/leo.db";
        mSqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(mPath, null);
    }

    public static ZeusDbHelper getInstance() {
        if (null == mInstance) {
            synchronized (ZeusDbHelper.class) {
                if (null == mInstance) {
                    mInstance = new ZeusDbHelper();
                }
            }
        }
        return mInstance;
    }


    public <T> IZeusDbDao<T> getZeusDbDao(Class<T> entityClass) {
        ZeusDbDao<T> dao = null;
        try {
            dao = ZeusDbDao.class.newInstance();
            dao.init(mSqLiteDatabase, entityClass);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return dao;
    }

}
